package com.yr.ryjk.focus;

import java.util.Map;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.doctor.entity.FilterParam;
import com.yr.ryjk.focus.service.IFocusService;
import com.yr.ryjk.interceptor.authority.For;
import com.yr.ryjk.interceptor.authority.UserType;
import com.yr.ryjk.util.JSONUtil;
/**
 * 关注
 * @author Rick
 *
 */
@For(user=UserType.APP_USER)
@Controller
@RequestMapping("/focus")
public class FocusController{
	@Autowired
	private IFocusService focusService;
	
	/**
	 * app用户关注/取消关注医生接口
	 * @param phone
	 * @param action 
	 * @param token 令牌
	 * @return
	 */
	@RequestMapping(value="/toggle",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> toggle(@RequestParam("phone") @NotBlank String phone,
			@RequestParam("action") @NotBlank int action,
			@RequestParam("token") @NotBlank String token){
		return focusService.updateToggle(phone, action, token);
	} 
	
	/**
	 * 分页查询用户关注的医生列表
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="/user/getFocus",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> listDoctor(@RequestParam(value="pageNo",defaultValue="1") int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize,
			@RequestParam("token") @NotBlank String token,
			FilterParam filterParam){
		return JSONUtil.getJSON(ErrorType.SUCCESS,
				focusService.getListOfPage(pageNo,pageSize,token,filterParam));
	}
	

	/**
	 * 分页查询医生被关注的用户列表
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="/doctor/getFocus",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> listFan(@RequestParam(value="pageNo",defaultValue="1") int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize,
			@RequestParam("token") @NotBlank String token){
		return JSONUtil.getJSON(ErrorType.SUCCESS,focusService.getListOfFan(pageNo,pageSize,token));
	}
}